<?php
namespace app\index\controller;
use think\Controller;
use think\Session;
use think\Request;
use think\View;
use think\Db;
use think\Model;

use PHPExcel;
use PHPExcel_IOFactory;
use PHPExcel_Writer_Excel5;
use PHPExcel_Style_Alignment;
use PHPExcel_Style_Fill;
use PHPExcel_Style_Border;
use PHPExcel_Cell_DataType;
//角色
class Role extends Common
{
    //菜单树保存
    public function poweredit($rid,$str){
        try{
            db("role")->where("id=$rid")->update(["power"=>$str]);
        }catch(\Exception $e){
            return 2;
        }
        return 1;
        
    }
    //菜单树
    public function powerlist($rid){
        $this->assign("rid",$rid);
         $role=db("role")->where("id=$rid")->value("power");
        if($role){
            $role=explode(',', $role);
        }else{
            $role=[];
        }
        $yiji=db("power")->order("index")->field("id,pid,title as name")->select();
        for($i=0;$i<count($yiji);$i++){
            if(in_array($yiji[$i]["id"], $role)){
                $yiji[$i]["checked"]=true;
            }else{
                $yiji[$i]["checked"]=false;
            }
        }
        $yiji=json_encode($yiji);
        $this->assign("yiji",$yiji);
        return $this->fetch();
    }
  
	public function huishou($page=1,$list=10){

		//接收数据
    	$request = Request::instance();

    	
    	$data=$request->post();
    	$where="r.is_actived=0 and r.is_deleted=0 ";

		

    	$sum=Db::table("role")->alias("r")->join("role rp","r.parent_id=rp.id","LEFT")->where($where)->count();

    	$maxpage=ceil($sum/$list);
        $page=$page<$maxpage?$page:$maxpage;
        $page=$page>1?$page:1;

        $start=($page-1)*$list;

        $roles=Db::table("role")->alias("r")
        ->join("role rp","r.parent_id=rp.id","LEFT")
        ->where($where)->order("r.id")->limit($start,$list)
        ->field("r.id,r.role_name,r.parent_id,r.remark,rp.role_name as prname")
        ->select();

       
		$this->assign("page",$page);
		$this->assign("list",$list);
		$this->assign("maxpage",$maxpage);
		$this->assign("sum",$sum);
		$this->assign("roles",$roles);
		return $this->fetch('huishou');

	}
    public function roledc(){
        $where="r.is_actived=1 and r.is_deleted=0 ";
        $roles=Db::table("role")->alias("r")
        ->join("role rp","r.parent_id=rp.id","LEFT")
        ->where($where)->order("r.id")
        ->field("r.id,r.role_name,r.parent_id,r.remark,rp.role_name as prname")
        ->select();
        $eid = Session::get("employee_id");
        $users = Db::table("employee")->where(["id" => $eid])->find();

        Vendor("PHPExcel");


        Vendor("PHPExcel.Writer.Excel5");

        // Loader::import('PHPExcel.Classes.PHPExcel');
        //Loader::import('PHPExcel.Classes.PHPExcel.IOFactory.PHPExcel_IOFactory');
        //  Vendor("Excel.PHPExcel.Writer.Excel2007");
        $objPHPExcel = new PHPExcel();


        $objProps = $objPHPExcel->getProperties();

        $objProps->setCreator('admin');
        $objProps->setLastModifiedBy('admin');
        $objProps->setTitle('Office 2003 XLSX Test Document');
        $objProps->setSubject('Office 2003 XLSX Test Document');
        $objProps->setDescription("Test document, generated by PHPExcel.");
        $objProps->setKeywords("office excel PHPExcel");
        $objProps->setCategory("Test");

        $objPHPExcel->setActiveSheetIndex(0);
        $objPHPExcel->getActiveSheet()->setTitle("角色列表");

        #################总标题

        $objPHPExcel->getActiveSheet()->getRowDimension('1')->setRowHeight(20);
        $objPHPExcel->getActiveSheet()->getRowDimension('2')->setRowHeight(20);
        $objPHPExcel->getActiveSheet()->mergeCells('A1:D1');
        $objPHPExcel->getActiveSheet()->setCellValue('A1', "角色列表");
        //水平剧中
        $objPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        //垂直剧中
        $objPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
        //加粗
        $objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true);
        //字体
        $objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setSize(14);
        #################表头信息
        $objPHPExcel->getActiveSheet()->mergeCells('A2:D2');
        $objPHPExcel->getActiveSheet()->setCellValue('A2', "(本表单由软件导出，导出时间：" . date("Y-m-d H:i:s") . "；导出人：{$users["em_name"]})");
        //水平剧中
        $objPHPExcel->getActiveSheet()->getStyle('A2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        //垂直剧中
        $objPHPExcel->getActiveSheet()->getStyle('A2')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
        //加粗
        $objPHPExcel->getActiveSheet()->getStyle('A2')->getFont()->setBold(true);
        //字体
        $objPHPExcel->getActiveSheet()->getStyle('A2')->getFont()->setSize(12);
        $objPHPExcel->getActiveSheet()->getStyle('3')->getAlignment()->setWrapText(true);
        
         $objPHPExcel->getActiveSheet()->getStyle('A3:D3')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
         $objPHPExcel->getActiveSheet()->getStyle('A3:D3')->getFill()->getStartColor()->setARGB('0099CCFF');
             //水平剧中
         $objPHPExcel->getActiveSheet()->getStyle('A3:D3')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
            //垂直剧中
         $objPHPExcel->getActiveSheet()->getStyle('A3:D3')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
         $objPHPExcel->getActiveSheet()->setCellValue('A3',"序号");
        $objPHPExcel->getActiveSheet()->setCellValue('B3',"角色名称");
        $objPHPExcel->getActiveSheet()->setCellValue('C3',"上级角色");
        $objPHPExcel->getActiveSheet()->setCellValue('D3',"备注");
         $h=3;
        for($i=0;$i<count($roles);$i++){
            $h++;
            $objPHPExcel->getActiveSheet()->setCellValueExplicit('A'.$h,$i+1,PHPExcel_Cell_DataType::TYPE_STRING);
            $objPHPExcel->getActiveSheet()->setCellValueExplicit('B'.$h,$roles[$i]["role_name"],PHPExcel_Cell_DataType::TYPE_STRING);
            $objPHPExcel->getActiveSheet()->setCellValueExplicit('C'.$h,$roles[$i]["prname"],PHPExcel_Cell_DataType::TYPE_STRING);
            $objPHPExcel->getActiveSheet()->setCellValueExplicit('D'.$h,$roles[$i]["remark"],PHPExcel_Cell_DataType::TYPE_STRING);
            
        }
         $styleArray = array(  
        'borders' => array(  
            'allborders' => array(  
                //'style' => PHPExcel_Style_Border::BORDER_THICK,//边框是粗的  
                'style' => PHPExcel_Style_Border::BORDER_THIN,//细边框  
                //'color' => array('argb' => 'FFFF0000'),  
            ),  
        ),  
    );  
            $objPHPExcel->getActiveSheet()->getStyle('A1:D'.$h)->applyFromArray($styleArray);//这里就是画出从单元格A5到N5的边框，看单元格最右边在哪哪
        //设置宽度
            $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(20);
            $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(20);
            $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(20);
            $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(20);
           
        //var_dump($objWriter);exit;
        $objWriter = new PHPExcel_Writer_Excel5($objPHPExcel);
        ob_end_clean();
        header("Pragma: public");
        header("Expires:0");
        header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
        header("Content-Type:application/force-download");
        header("Content-Type:application/vnd.ms-execl");
        header("Content-Type:application/octet-stream");
        header("Content-Type:application/download");
        header('Content-Disposition:attachment;filename=file.xls');
        header("Content-type:text/html;charset=utf-8");
        header("Content-Transfer-Encoding:binary");
        $objWriter->save('php://output');
    }
	public function manage($page=1,$list=10){

		//接收数据
    	$request = Request::instance();

    	
    	$data=$request->post();
    	$where="r.is_actived=1 and r.is_deleted=0 ";

		if($data){
    		
    		if(trim($data["role_name"]))
    			$where.="and r.role_name like '%{$data["role_name"]}%' ";
    		if(trim($data["prname"]))
    			$where.="and rp.role_name like '%{$data["prname"]}%' ";
    		
    	}else{
    		$data=["role_name"=>"","prname"=>""];
    	}

    	$sum=Db::table("role")->alias("r")->join("role rp","r.parent_id=rp.id","LEFT")->where($where)->count();

    	$maxpage=ceil($sum/$list);
        $page=$page<$maxpage?$page:$maxpage;
        $page=$page>1?$page:1;

        $start=($page-1)*$list;

        $roles=Db::table("role")->alias("r")
        ->join("role rp","r.parent_id=rp.id","LEFT")
        ->where($where)->order("r.id")->limit($start,$list)
        ->field("r.id,r.role_name,r.parent_id,r.remark,rp.role_name as prname")
        ->select();

        $this->assign("data",$data);
		$this->assign("page",$page);
		$this->assign("list",$list);
		$this->assign("maxpage",$maxpage);
		$this->assign("sum",$sum);
		$this->assign("roles",$roles);
		return $this->fetch('manage');

	}
	//删除角色
	public function dropr(){
		$request = Request::instance();
        
        $data=$request->post();//接收数据
        //print_r($data);exit;
        //$data["m_users_id"]=Session::get("login_id");
			//$data["modifiled_on"]=date("Y-m-d H:i:s");
       //判断角色是否被使用
       $has=db("users_role ur")->join("users u","ur.users_id=u.id")->where(["ur.role_id"=>$data["rid"],"u.state"=>1])->find();
       if($has){
            return json_encode(["msg"=>"该角色已被使用，请先处理","state"=>2]);
       }else{
            //查看下级角色
            $hasnext=db("role")->where("path like '%[{$data["rid"]}]%' and is_actived=1")->find();
            if($hasnext){
                return json_encode(["msg"=>"该角色存在未被删除的下级角色，请先处理","state"=>2]);
            }else{
                $where=["id"=>$data["rid"],"is_actived"=>0,"modifiled_on"=>date("Y-m-d H:i:s")];
                $res=Db::table("role")->update($where);
                db("users_role")->where(["role_id"=>$data["rid"]])->delete();
                if($res)
                    return json_encode(["msg"=>"","state"=>1]);
                else
                    return json_encode(["msg"=>"系统繁忙请稍候再试","state"=>2]);
            }
            
       }
		
	}
	//恢复角色
	public function huifur(){
		$request = Request::instance();
        
        $data=$request->post();//接收数据
        //print_r($data);exit;
        //$data["m_users_id"]=Session::get("login_id");
			//$data["modifiled_on"]=date("Y-m-d H:i:s");
            //查看是否有未回复的上级
        $role=db("role")->where("id={$data["rid"]}")->find();
        $pid=$role["parent_id"];
        if($pid){
            $hasp=db("role")->where(["id"=>$pid,"is_actived"=>0])->find();
        }else{
            $hasp=[];
        }
        if($hasp){
            return json_encode(["msg"=>"存在未恢复的上级角色，请优先处理","state"=>2]);
        }else{
            $where=["id"=>$data["rid"],"is_actived"=>1,"modifiled_on"=>date("Y-m-d H:i:s")];
            $res=Db::table("role")->update($where);
            if($res)
                return json_encode(["msg"=>"","state"=>1]);
            else
                return json_encode(["msg"=>"系统繁忙请稍候再试","state"=>2]);
        }
		
	}
	public function huishougroup($page=1,$list=10){
				//接收数据
    	$request = Request::instance();

    	
    	$data=$request->post();

    	$where="rg.is_actived=0 and rg.is_deleted=0 and r.is_deleted=0 and r.is_actived=1 ";
    
    	$arr=Db::table("role_group")->alias("rg")
    	->join("role_edit re","rg.id=re.group_id","LEFT")
    	->join("role r","re.role_id=r.id","LEFT")
    	->where($where)->distinct("rg.id")->field("rg.id")->select();
    	$sum=count($arr);
    	$maxpage=ceil($sum/$list);
        $page=$page<$maxpage?$page:$maxpage;
        $page=$page>1?$page:1;

        $start=($page-1)*$list;
        $rgarr=Db::table("role_group")->alias("rg")
    	->join("role_edit re","rg.id=re.group_id","LEFT")
    	->join("role r","re.role_id=r.id","LEFT")
    	->where($where)
    	->order("rg.id")
    	->limit($start,$list)->distinct("rg.id")->field("rg.id,rg.group_name,rg.remark")->select();

    	$rgids=[];
    	for($i=0;$i<count($rgarr);$i++){

    		$rgids[]=$rgarr[$i]["id"];
    	}
    	if($rgids){
    		$str=implode(',',$rgids);
    		$rolearr=Db::table("role")->alias("r")->join("role_edit re","r.id=re.role_id")->where("group_id in($str) and r.is_actived=1 and r.is_deleted=0")->field("r.role_name,re.group_id")->select();
    	}else{
    		$rolearr=[];
    	}
    	
    	$this->assign("page",$page);
		$this->assign("list",$list);
		$this->assign("maxpage",$maxpage);
		$this->assign("sum",$sum);
		$this->assign("rolearr",$rolearr);
		$this->assign("rgarr",$rgarr);
		return $this->fetch('huishougroup');
	}
    //角色组导出
    public function rgdc(){
        $where="rg.is_actived=1 and rg.is_deleted=0 and r.is_deleted=0 and r.is_actived=1 ";
        $rgarr=Db::table("role_group")->alias("rg")
        ->join("role_edit re","rg.id=re.group_id","LEFT")
        ->join("role r","re.role_id=r.id","LEFT")
        ->where($where)
        ->order("rg.id")
        ->distinct("rg.id")->field("rg.id,rg.group_name,rg.remark")->select();

        for($i=0;$i<count($rgarr);$i++){
            $role=Db::table("role")->alias("r")->join("role_edit re","r.id=re.role_id")->where("group_id={$rgarr[$i]["id"]} and r.is_actived=1 and r.is_deleted=0")->field("r.role_name")->select();
            if($role){
                $rolearr=[];
                foreach ($role as $k => $v) {
                    # code...
                    $rolearr[]=$v["role_name"];
                }
                $rgarr[$i]["role"]=implode(',',$rolearr);
            }else{
                $rgarr[$i]["role"]="";
            }

            

        }
        $eid = Session::get("employee_id");
        $users = Db::table("employee")->where(["id" => $eid])->find();

        Vendor("PHPExcel");


        Vendor("PHPExcel.Writer.Excel5");

        // Loader::import('PHPExcel.Classes.PHPExcel');
        //Loader::import('PHPExcel.Classes.PHPExcel.IOFactory.PHPExcel_IOFactory');
        //  Vendor("Excel.PHPExcel.Writer.Excel2007");
        $objPHPExcel = new PHPExcel();


        $objProps = $objPHPExcel->getProperties();

        $objProps->setCreator('admin');
        $objProps->setLastModifiedBy('admin');
        $objProps->setTitle('Office 2003 XLSX Test Document');
        $objProps->setSubject('Office 2003 XLSX Test Document');
        $objProps->setDescription("Test document, generated by PHPExcel.");
        $objProps->setKeywords("office excel PHPExcel");
        $objProps->setCategory("Test");

        $objPHPExcel->setActiveSheetIndex(0);
        $objPHPExcel->getActiveSheet()->setTitle("角色组列表");
         #################总标题

        $objPHPExcel->getActiveSheet()->getRowDimension('1')->setRowHeight(20);
        $objPHPExcel->getActiveSheet()->getRowDimension('2')->setRowHeight(20);
        $objPHPExcel->getActiveSheet()->mergeCells('A1:D1');
        $objPHPExcel->getActiveSheet()->setCellValue('A1', "部门列表");
        //水平剧中
        $objPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        //垂直剧中
        $objPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
        //加粗
        $objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true);
        //字体
        $objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setSize(14);
        #################表头信息
        $objPHPExcel->getActiveSheet()->mergeCells('A2:D2');
        $objPHPExcel->getActiveSheet()->setCellValue('A2', "(本表单由软件导出，导出时间：" . date("Y-m-d H:i:s") . "；导出人：{$users["em_name"]})");
        //水平剧中
        $objPHPExcel->getActiveSheet()->getStyle('A2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        //垂直剧中
        $objPHPExcel->getActiveSheet()->getStyle('A2')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
        //加粗
        $objPHPExcel->getActiveSheet()->getStyle('A2')->getFont()->setBold(true);
        //字体
        $objPHPExcel->getActiveSheet()->getStyle('A2')->getFont()->setSize(12);
        $objPHPExcel->getActiveSheet()->getStyle('3')->getAlignment()->setWrapText(true);
        
         $objPHPExcel->getActiveSheet()->getStyle('A3:D3')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
         $objPHPExcel->getActiveSheet()->getStyle('A3:D3')->getFill()->getStartColor()->setARGB('0099CCFF');
             //水平剧中
         $objPHPExcel->getActiveSheet()->getStyle('A3:D3')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
            //垂直剧中
         $objPHPExcel->getActiveSheet()->getStyle('A3:D3')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);

        $objPHPExcel->getActiveSheet()->setCellValue('A3',"序号");
        $objPHPExcel->getActiveSheet()->setCellValue('B3',"角色组名");
        $objPHPExcel->getActiveSheet()->setCellValue('C3',"包含角色");
        $objPHPExcel->getActiveSheet()->setCellValue('D3',"备注");

         $h=3;
        for($i=0;$i<count($rgarr);$i++){
            $h++;
            $objPHPExcel->getActiveSheet()->setCellValueExplicit('A'.$h,$i+1,PHPExcel_Cell_DataType::TYPE_STRING);
            $objPHPExcel->getActiveSheet()->setCellValueExplicit('B'.$h,$rgarr[$i]["group_name"],PHPExcel_Cell_DataType::TYPE_STRING);
            $objPHPExcel->getActiveSheet()->setCellValueExplicit('C'.$h,$rgarr[$i]["role"],PHPExcel_Cell_DataType::TYPE_STRING);
            $objPHPExcel->getActiveSheet()->setCellValueExplicit('D'.$h,$rgarr[$i]["remark"],PHPExcel_Cell_DataType::TYPE_STRING);
           
            
        }
         $styleArray = array(  
        'borders' => array(  
            'allborders' => array(  
                //'style' => PHPExcel_Style_Border::BORDER_THICK,//边框是粗的  
                'style' => PHPExcel_Style_Border::BORDER_THIN,//细边框  
                //'color' => array('argb' => 'FFFF0000'),  
            ),  
        ),  
    );  
            $objPHPExcel->getActiveSheet()->getStyle('A1:D'.$h)->applyFromArray($styleArray);//这里就是画出从单元格A5到N5的边框，看单元格最右边在哪哪
        //设置宽度
            $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(20);
            $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(20);
            $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(40);
            $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(20);
           
        //var_dump($objWriter);exit;
        $objWriter = new PHPExcel_Writer_Excel5($objPHPExcel);
        ob_end_clean();
        header("Pragma: public");
        header("Expires:0");
        header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
        header("Content-Type:application/force-download");
        header("Content-Type:application/vnd.ms-execl");
        header("Content-Type:application/octet-stream");
        header("Content-Type:application/download");
        header('Content-Disposition:attachment;filename=file.xls');
        header("Content-type:text/html;charset=utf-8");
        header("Content-Transfer-Encoding:binary");
        $objWriter->save('php://output');
    }
	//角色组管理
	public function managegroup($page=1,$list=10){
			//接收数据
    	$request = Request::instance();

    	
    	$data=$request->post();

    	$where="rg.is_actived=1 and rg.is_deleted=0 and r.is_deleted=0 and r.is_actived=1 ";
    	if($data){
    		
    		if(trim($data["role_name"]))
    			$where.="and r.role_name like '%{$data["role_name"]}%' ";
    		if(trim($data["group_name"]))
    			$where.="and rg.group_name like '%{$data["group_name"]}%' ";
    		
    	}else{
    		$data=["role_name"=>"","group_name"=>""];
    	}
    	$arr=Db::table("role_group")->alias("rg")
    	->join("role_edit re","rg.id=re.group_id","LEFT")
    	->join("role r","re.role_id=r.id","LEFT")
    	->where($where)->distinct("rg.id")->field("rg.id")->select();
    	$sum=count($arr);
    	$maxpage=ceil($sum/$list);
        $page=$page<$maxpage?$page:$maxpage;
        $page=$page>1?$page:1;

        $start=($page-1)*$list;
        $rgarr=Db::table("role_group")->alias("rg")
    	->join("role_edit re","rg.id=re.group_id","LEFT")
    	->join("role r","re.role_id=r.id","LEFT")
    	->where($where)
    	->order("rg.id")
    	->limit($start,$list)->distinct("rg.id")->field("rg.id,rg.group_name,rg.remark")->select();

    	$rgids=[];
    	for($i=0;$i<count($rgarr);$i++){

    		$rgids[]=$rgarr[$i]["id"];
    	}
    	if($rgids){
    		$str=implode(',',$rgids);
    		$rolearr=Db::table("role")->alias("r")->join("role_edit re","r.id=re.role_id")->where("group_id in($str) and r.is_actived=1 and r.is_deleted=0")->field("r.role_name,re.group_id")->select();
    	}else{
    		$rolearr=[];
    	}
    	$this->assign("data",$data);
    	$this->assign("page",$page);
		$this->assign("list",$list);
		$this->assign("maxpage",$maxpage);
		$this->assign("sum",$sum);
		$this->assign("rolearr",$rolearr);
		$this->assign("rgarr",$rgarr);
		return $this->fetch('managegroup');
	}
	//删除角色组
	public function droprg(){
		$request = Request::instance();
        
        $data=$request->post();//接收数据
        //print_r($data);exit;
        //$data["m_users_id"]=Session::get("login_id");
			//$data["modifiled_on"]=date("Y-m-d H:i:s");
        //判断角色组是否被使用
        $has=db("users_role_group ug")->join("users u","ug.users_id=u.id")->where(["ug.role_group_id"=>$data["rgid"],"u.state"=>1])->find();
        if($has){
            return json_encode(["msg"=>"该角色组已被使用，请先处理","state"=>2]);
        }else{
            $where=["id"=>$data["rgid"],"is_actived"=>0,"modifiled_on"=>date("Y-m-d H:i:s")];
            $res=Db::table("role_group")->update($where);
            db("users_role_group")->where(["role_group_id"=>$data["rgid"]])->delete();
            if($res)
                return json_encode(["msg"=>"","state"=>1]);
            else
                return json_encode(["msg"=>"系统繁忙请稍候再试","state"=>2]);
        }
		
	}
	//恢复角色组
	public function huifurg(){
		$request = Request::instance();
        
        $data=$request->post();//接收数据
        //print_r($data);exit;
        //$data["m_users_id"]=Session::get("login_id");
			//$data["modifiled_on"]=date("Y-m-d H:i:s");
		$where=["id"=>$data["rgid"],"is_actived"=>1,"modifiled_on"=>date("Y-m-d H:i:s")];
		$res=Db::table("role_group")->update($where);
		if($res)
			return 1;
		else
			return 2;
	}
}